<template>
	<el-container class="color" :style="{ height: (h + 'px') }">
		<el-header class="image-header">
			<el-button type="primary" size="small" @click="handleOpenCreate">新增图片分类</el-button>
			<el-button type="warning" size="small" @click="handleOpenUpload">上传图片</el-button>
		</el-header>
		<el-container>
			<ImageAside ref="ImageAsideRef" @change="handleAsideChange" />
			<ImageMain ref="ImageMainRef" />
		</el-container>
	</el-container>
</template>

<script setup>
	import {
		ref,
		nextTick
	} from 'vue';
	import ImageAside from '~/components/ImageAside.vue';
	import ImageMain from '~/components/ImageMain.vue';

	const windowHeight = window.innerHeight || document.body.clientHeight;
	const h = windowHeight - 64 - 44;

	const ImageAsideRef = ref(null);
	

	const handleOpenCreate = async () => {
		await nextTick(); // 确保组件挂载完成
		if (ImageAsideRef.value) {
			ImageAsideRef.value.handleCreate();
		}
	};

	const ImageMainRef = ref(null)

	const handleAsideChange = async (image_class_id) => {
		await nextTick(); // 确保 ImageMain 组件挂载完成
		if (ImageMainRef.value) {
			ImageMainRef.value.loadData(image_class_id);
		} else {
			console.warn('ImageMain 组件尚未挂载，无法调用 loadData 方法');
		}
	};

	const handleOpenUpload = () => ImageMainRef.value.openUploadFile()
</script>

<style scoped>
	.color {
		background-color: #fff;
		border-radius: 0.25rem;
	}

	.image-header {
		border-bottom: 1px solid #eeeeee;
		display: flex;
		align-items: center;
	}
</style>